//
//  DiaryViewModel.swift
//  ShouChong
//
//  Created by yw on 2024/8/15.
//

import Foundation

class DiaryModel:SQLModel,Identifiable{
    var content:String = ""
    var dateString:String = ""
    var modelId:String = UUID().uuidString
}

class DiaryViewModel:ObservableObject {
    @Published var list:[DiaryModel] = []
    
    
    init() {
        getList()
    }
    
    func getList() {
        
        list = DiaryModel.rows().reversed()
    }
    
    func addRow(content:String,dateString:String) {
        let model = DiaryModel()
        model.content = content
        model.dateString = dateString
        model.save()
        getList()
    }
    
    func deleteRow(model:DiaryModel) {
        DiaryModel.remove(filter: "modelId=\"\(model.modelId)\"")
        getList()
    }
    
    func deleteAllRow() {
        DiaryModel.remove()
    }
}
